//-----------------------------------------------------------------------
// <copyright file="CollaborateService.cs" company="Simnova LLC">
//     Copyright (c) Simnova LLC. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Simnova.Collaborate.ServiceImplementation
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using System.ServiceModel.Description;
    using System.Configuration;
    using Simnova.Collaborate.ServiceContract;
    using Simnova.Collaborate.ServiceContract.DataClasses;
    using Simnova.Collaborate.Reports.Proxy;

    ////public class ProjectServiceHost : ServiceHostBase
    ////{
    ////    protected override void InitializeRuntime()
    ////    {
    ////        VirtualPathExtension extension = this.Extensions.Find<VirtualPathExtension>();
    ////        base.InitializeRuntime();
    ////    }
    ////    protected override ServiceDescription CreateDescription(out IDictionary<string, ContractDescription> implementedContracts)
    ////    {
    ////        implementedContracts = null;
    ////        return new ServiceDescription();
    ////    }
    ////}
    
    public class CollaborateService : ServiceContract.ServiceContracts.ICollaborateService
    {
        #region Reports

        public byte[] ExecuteReport(string report, IList<ReportParameter> reportParameters, string reportFormat)
        {
            return Simnova.Collaborate.Reports.Proxy.Report.ExecuteReport(report, reportParameters, reportFormat);
        }

        #endregion

        #region Feedback

        public IList<Product> GetProductsByCompany(int companyId)
        {
            return DataProvider.Instance().GetProductsByCompany(companyId);
        }

        public Product GetProduct(int productId)
        {
            return DataProvider.Instance().GetProduct(productId);
        }

        public Feedback GetFeedback(int feedbackId)
        {
            return DataProvider.Instance().GetFeedback(feedbackId);
        }

        public FeedbackComment GetFeedbackCommentByFeedback(int userId, int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackCommentByFeedback(userId, feedbackId);
        }

        public FeedbackRating GetFeedbackRatingByFeedback(int userId, int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackRatingByFeedback(userId, feedbackId);
        }

        public FeedbackWatchList GetFeedbackWatchListByFeedback(int userId, int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackWatchListByFeedback(userId, feedbackId);
        }

        public FeedbackWorkaround GetFeedbackWorkaroundByFeedback(int userId, int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackWorkaroundByFeedback(userId, feedbackId);
        }

        public IList<Feedback> GetProductFeedback(int productId)
        {
            return DataProvider.Instance().GetProductFeedback(productId);
        }

        public IList<Feedback> GetTopRatedProductFeedback(int productId, int quantity)
        {
            return DataProvider.Instance().GetTopRatedProductFeedback(productId, quantity);
        }

        public IList<Feedback> GetWatchListProductFeedback(int productId, int userId, int quantity)
        {
            return DataProvider.Instance().GetWatchListProductFeedback(productId, userId, quantity);
        }

        public IList<Feedback> GetNewestProductFeedback(int productId, int quantity)
        {
            return DataProvider.Instance().GetNewestProductFeedback(productId, quantity);
        }

        public IList<Feedback> GetProductFeedbackByUser(int productId, int userId)
        {
            return DataProvider.Instance().GetProductFeedbackByUser(productId, userId);
        }

        public IList<FeedbackWatchList> GetFeedbackWatchListByUser(int productId, int userId)
        {
            return DataProvider.Instance().GetFeedbackWatchListByUser(productId, userId);
        }

        public IList<FeedbackComment> GetFeedbackComments(int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackComments(feedbackId);
        }

        public IList<FeedbackRating> GetFeedbackRatings(int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackRatings(feedbackId);
        }

        public IList<FeedbackWorkaround> GetFeedbackWorkarounds(int feedbackId)
        {
            return DataProvider.Instance().GetFeedbackWorkarounds(feedbackId);
        }

        public void SaveProduct(Product product)
        {
            DataProvider.Instance().SaveProduct(product);
        }

        public void SaveFeedback(Feedback feedback)
        {
            DataProvider.Instance().SaveFeedback(feedback);
        }

        public void SaveFeedbackComment(FeedbackComment feedbackComment)
        {
            DataProvider.Instance().SaveFeedbackComment(feedbackComment);
        }

        public void SaveFeedbackRating(FeedbackRating feedbackRating)
        {
            DataProvider.Instance().SaveFeedbackRating(feedbackRating);
        }

        public void SaveFeedbackWatchList(FeedbackWatchList feedbackWatchList)
        {
            DataProvider.Instance().SaveFeedbackWatchList(feedbackWatchList);
        }

        public void DeleteFeedbackWatchList(FeedbackWatchList feedbackWatchList)
        {
            DataProvider.Instance().DeleteFeedbackWatchList(feedbackWatchList);
        }

        public void SaveFeedbackWorkaround(FeedbackWorkaround feedbackWorkaround)
        {
            DataProvider.Instance().SaveFeedbackWorkaround(feedbackWorkaround);
        }

        #endregion

        #region Company
        public Company GetCompany(int companyId)
        {
            return DataProvider.Instance().GetCompany(companyId);
        }

        public void SaveCompany(Company company, int userId)
        {
            DataProvider.Instance().SaveCompany(company, userId);
        }

        public IList<Company> GetCompanies()
        {
            return DataProvider.Instance().GetCompanies();
        }
        #endregion

        #region Project
       
        public Project GetProject(int projectId)
        {
            return DataProvider.Instance().GetProject(projectId);
        }

        public void SaveProject(Project project)
        {
            DataProvider.Instance().SaveProject(project);
        }

        public IList<Project> GetProjectsByCompany(int companyId)
        {
            return DataProvider.Instance().GetProjectsByCompany(companyId);
        }

        #endregion

        #region Task

        public Task GetTask(int taskId)
        {
            return DataProvider.Instance().GetTask(taskId);
        }

        public void SaveTask(Task task)
        {
            DataProvider.Instance().SaveTask(task);
        }

        public IList<Task> GetTasksByProject(int projectId)
        {
            return DataProvider.Instance().GetTasksByProject(projectId);
        }

        public IList<Task> Tasks(int userId)
        {
            return DataProvider.Instance().GetTasksByUser(userId);
        }

        public IList<Task> GetTasksByUser(int userId)
        {
            return DataProvider.Instance().GetTasksByUser(userId);
        }

        #endregion

        #region User

        public User GetUserById(int userId)
        {
            return DataProvider.Instance().GetUserById(userId);
        }

        public User GetUser(string emailAddress, string password)
        {
            User user = DataProvider.Instance().GetUserByEmailAddress(emailAddress);
            if (user == null) //email address does not correspond to account
            {
                return null;
            }
            if (user.PasswordSalt == null) // salt wasn't created, create one..
            {
                SaveUser(user);
            }
            if (user.Password == Cryptographer.HashPassword(password, user.PasswordSalt)) // check to see if login is valid
            {
                return user;
            }
            else
            {
                return null;
            }
        }

        public void SaveUser(User user)
        {
            if (user.PasswordSalt == null)
            {
                user.PasswordSalt = Cryptographer.CreateSalt();
                user.Password = Cryptographer.HashPassword(user.Password, user.PasswordSalt);
            }
            DataProvider.Instance().SaveUser(user);
        }

        public IList<CompanyUser> GetCompanyUsersByCompany(int companyId)
        {
            return DataProvider.Instance().GetCompanyUsersByCompany(companyId);
        }

        public IList<User> GetUsers()
        {
            return DataProvider.Instance().GetUsers();
        }

        public IList<Company> GetCompaniesByAdministrator(int userId)
        {
            return DataProvider.Instance().GetCompaniesByAdministrator(userId);
        }

        public IList<Company> GetCompaniesByUser(int userId)
        {
            return DataProvider.Instance().GetCompaniesByUser(userId);
        }

        public void SaveUserRole(UserRole userRole)
        {
            DataProvider.Instance().SaveUserRole(userRole);
        }

        public void SaveActivityType(ActivityType activityType)
        {
            DataProvider.Instance().SaveActivityType(activityType);
        }

        public IList<ActivityType> GetActivityTypesByRole(int roleId)
        {
            return DataProvider.Instance().GetActivityTypesByRole(roleId);
        }

        public IList<Role> GetRolesByCompany(int companyId)
        {
            return DataProvider.Instance().GetRolesByCompany(companyId);
        }

        public IList<Role> GetRolesByUserCompany(int userId, int companyId)
        {
            return DataProvider.Instance().GetRolesByUserCompany(userId, companyId);
        }

        public void SaveRole(Role role)
        {
            DataProvider.Instance().SaveRole(role);
        }

        #endregion

        #region TimeLog
 
        public IList<TimeLog> GetTimeLogByUser(int userId)
        {
            return DataProvider.Instance().GetTimeLogByUser(userId);
        }

        public TimeLog GetCurrentTimeLog(int userId)
        {
            return DataProvider.Instance().GetCurrentTimeLog(userId);
        }

        public void SaveTimeLog(TimeLog timeLog)
        {
            DataProvider.Instance().SaveTimeLog(timeLog);
        }

        public void DeleteTimeLog(TimeLog timeLog)
        {
            DataProvider.Instance().DeleteTimeLog(timeLog);
        }

        #endregion

        public void WeeklyReport()
        {
        }
    }
}

